package session;

import entity.Esame;
import entity.PianoStudio;
import facade.DocenteFacadeLocal;
import facade.EsameFacadeLocal;
import facade.StudenteFacadeLocal;

import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author grillo
 */
@Stateless
public class ListaEsamiBean implements ListaEsamiLocal {
    @EJB
    private StudenteFacadeLocal studenteFacade;
    @EJB
    private DocenteFacadeLocal docenteFacade;
    @EJB
    private EsameFacadeLocal esameFacade;

    public List<Esame> getListaEsami() {
        try {
            List<Esame> lista = new LinkedList();
            lista = esameFacade.findAll();
            return lista;
        } catch (Exception e) {
            return null;
        }
    }

    public List<Esame> getListaEsamiByMatricola(Integer matricola, String user) {
        try {
            List<Esame> lista = new LinkedList();
            if(user.equalsIgnoreCase("ST")) {
                List<PianoStudio> piano = studenteFacade.find(matricola).getPianoStudioCollection();
                lista = new LinkedList();
                for(PianoStudio p : piano)
                    lista.add(p.getEsame());
                return lista;
            }
            if(user.equalsIgnoreCase("DO")) {
                lista = docenteFacade.find(matricola).getEsameCollection();
                return lista;
            }
            return lista;
        } catch (Exception e) {
            return null;
        }
    }
}
